package com.koron.order.change.controller;

import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.order.change.bean.dto.OrderChangeDto;
import com.koron.order.change.bean.po.OrderChangePo;
import com.koron.order.change.bean.query.OrderChangeQuery;
import com.koron.order.change.bean.vo.OrderChangeDetailVo;
import com.koron.order.change.bean.vo.OrderChangeVo;
import com.koron.order.change.service.OrderChangeService;
import com.koron.order.common.service.OrderDispatchInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * (OrderChange)表控制层
 *
 * @author zhouj
 * @since 2022-02-16 18:14:28
 */
@Api(tags = "工单变更(OrderChange)")
@RestController
@RequestMapping("/orderChange/")
public class OrderChangeController {

    @Autowired
    private OrderChangeService orderChangeService;

    @Autowired
    OrderDispatchInfoService orderDispatchInfoService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @ApiOperation(value = "新增或修改")
    @PostMapping("insertOrUpdate")
    public Response<OrderChangePo> insertOrUpdate(@RequestBody OrderChangeDto orderChangeDto) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderChangeService, "insertOrUpdate", OrderChangePo.class, orderChangeDto));
    }

    @ApiOperation(value = "新增")
    @PostMapping("insert")
    public Response<Integer> insert(@RequestBody OrderChangePo orderChange) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderChangeService, "insert", Integer.class, orderChange));
    }

    @ApiOperation(value = "批量新增")
    @PostMapping("insertBatch")
    public Response<Integer> insertBatch(@RequestBody List<OrderChangePo> orderChangeList) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderChangeService, "insertBatch", Integer.class, orderChangeList));
    }

    @ApiOperation(value = "根据id更新")
    @PutMapping("update")
    public Response<Integer> update(@RequestBody OrderChangePo orderChange) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderChangeService, "update", Integer.class, orderChange));
    }

    @ApiOperation(value = "根据id删除")
    @DeleteMapping("deleteById")
    public Response<Integer> deleteById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderChangeService, "deleteById", Integer.class, id));
    }

    @ApiOperation(value = "根据id查询")
    @GetMapping("queryById")
    public Response<OrderChangeDetailVo> queryById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderChangeService, "queryById", OrderChangeDetailVo.class, id));
    }

    @ApiOperation(value = "不分页查询列表")
    @GetMapping("queryList")
    public Response<List<OrderChangeVo>> queryList(OrderChangeQuery query) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderChangeService, "queryList", List.class, query));
    }

    @ApiOperation(value = "分页查询列表")
    @GetMapping("queryPageList")
    public Response<PageInfo<OrderChangeVo>> queryPageList(OrderChangeQuery query, PageQuery pageQuery) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderChangeService, "queryPageList", PageInfo.class, query, pageQuery));
    }

}
